<?php

/**
* 在文章撰写页增加这篇文章属于哪一类人看的下拉选项，给出的专属名是reader
*/
function reader(){
	global $post;
	//在文章中打印该文章的适读人群
	$reader = get_post_meta($post->ID,'_reader',true);
	$url = '';
	if($reader == '入门菜')$url = get_bloginfo('url').'/preschooler';
	if($reader == '初学者')$url = get_bloginfo('url').'/beginner';
	if($reader == '前端手')$url = get_bloginfo('url').'/frontendholder';
	if($reader == '程序猿')$url = get_bloginfo('url').'/programmer';
	if($reader == '运维鸟')$url = get_bloginfo('url').'/wareholder';
	if($reader == '工程师')$url = get_bloginfo('url').'/engineer';
	if($reader == '设计师')$url = get_bloginfo('url').'/stylist';
	if($reader == '运营家')$url = get_bloginfo('url').'/webmanager';
	if($reader == '观察员')$url = get_bloginfo('url').'/assayer';
	if($reader == '项目人')$url = get_bloginfo('url').'/projecter';
	echo get_interpret('适读人群：').'<a href="'.$url.'">'.$reader.'</a>';
}
add_action( 'add_meta_boxes', 'reader_add_custom_box',0,0 );
add_action( 'save_post', 'reader_save_postdata' );
function reader_add_custom_box() {
    add_meta_box( 
        'reader_sectionid',
        '适读人群',
        'reader_inner_custom_box',
        'post' 
    );
}
function reader_inner_custom_box( $post ) {
  wp_nonce_field( plugin_basename( __FILE__ ), 'reader_noncename' );
  $reader = get_post_meta($post->ID,'_reader',true);
?>
<select id="reader_new_field" name="reader_new_field">
	<option<?php if($reader == '观察员')echo ' selected="selected"'; ?>>观察员</option>
	<option<?php if($reader == '入门菜')echo ' selected="selected"'; ?>>入门菜</option>
	<option<?php if($reader == '初学者')echo ' selected="selected"'; ?>>初学者</option>
	<option<?php if($reader == '前端手')echo ' selected="selected"'; ?>>前端手</option>
	<option<?php if($reader == '程序猿')echo ' selected="selected"'; ?>>程序猿</option>
	<option<?php if($reader == '运维鸟')echo ' selected="selected"'; ?>>运维鸟</option>
	<option<?php if($reader == '工程师')echo ' selected="selected"'; ?>>工程师</option>
	<option<?php if($reader == '设计师')echo ' selected="selected"'; ?>>设计师</option>
	<option<?php if($reader == '运营家')echo ' selected="selected"'; ?>>运营家</option>
	<option<?php if($reader == '项目人')echo ' selected="selected"'; ?>>项目人</option>
</select>
<?php
}
function reader_save_postdata( $post_id ) {
  if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
  if ( !wp_verify_nonce( $_POST['reader_noncename'], plugin_basename( __FILE__ ) ) )return;
  $mydata = $_POST['reader_new_field'];
  add_post_meta($post_id,'_reader',$mydata,true) or update_post_meta($post_id,'_reader',$mydata);
}
?>